<template>
  <div class="app-container">
    <div class="app-form">
      <store
        :extra="extra"
        :order="order"
        @request="handleRequest"
        @closePage="closePage"
      />
    </div>
  </div>
</template>

<script>
import { placeCreate, placeTypeList } from '@projectName/views/diandi_place/api/place/place'
import store from '@/components/Bloc/store.vue'
import { enumsInit } from '../../api/Enums'
export default {
  components: {
    store
  },
  data() {
    return {
      order: [
        'bloc_id',
        'type',
        'name',
        'logo',
        'provinceCityDistrict',
        'address',
        'longitude',
        'latitude',
        'mobile',
        'status',
        'label_link',
        'displayorder',
        'device',
        'lanuage',
        'level',
        'mail',
        'roomcount',
        'sales',
        'thumb',
        'thumbs',
        'traffic'
      ],
      extra: {
        bloc_id: {
          label: '选择品牌',
          // 只需要在这里指定为 tree-select 即可
          type: 'cascader-bloc'
        },
        type: {
          type: 'radio',
          label: '楼栋类型',
          options: enumsInit().then((res) => {
            return res.data.PlaceTypeEnums
          })
        },
        name: {
          type: 'input',
          label: '楼栋名称'
        },
        logo: {
          label: '楼栋LOGO',
          type: 'image-uploader' // 只需要在这里指定为 image-uploader 即可
        },
        displayorder: {
          type: 'input',
          label: '排序'
        },
        device: {
          type: 'input',
          label: '服务设施'
        },
        lanuage: {
          type: 'radio',
          label: '房东语言',
          options: enumsInit().then((res) => {
            return res.data.LanguageEnums
          })
        },
        level: {
          type: 'input',
          label: '楼栋星级'
        },
        mail: {
          type: 'input',
          label: '联系邮箱'
        },
        roomcount: {
          type: 'input',
          label: '房间总量',
          attrs: {
            type: 'number'
          }
        },
        sales: {
          type: 'input',
          label: 'Sales'
        },
        lease_type: {
          label: '出租方式',
          // 只需要在这里指定为 tree-select 即可
          type: 'tree-select',
          // 属性参考: https://vue-treeselect.js.org/
          attrs: {
            multiple: false,
            clearable: true
          },
          options: async data => {
            const res = await enumsInit(0)
            return res.data.LesseeEnums
          }
        },
        time_length: {
          label: '出租时长',
          // 只需要在这里指定为 tree-select 即可
          type: 'tree-select',
          // 属性参考: https://vue-treeselect.js.org/
          attrs: {
            multiple: false,
            clearable: true
          },
          options: async data => {
            const res = await enumsInit(0)
            const arr = [{
              id: 0,
              label: '不限时长'
            }]
            return arr.concat(res.data.TimelengthEnums)
          }
        },
        price: {
          type: 'input',
          label: '价格',
          attrs: {
            type: 'number'
          }
        },
        status: {
          type: 'radio',
          label: '状态:楼栋状态',
          isOptions: true,
          options: [
            {
              text: '开启',
              value: 1
            },
            {
              text: '关闭',
              value: 2
            }
          ]
        },
        thumb: {
          type: 'image-uploader',
          label: '楼栋图片'
        },
        thumbs: {
          type: 'image-uploader',
          label: '楼栋相册',
          attrs: {
            multiple: true,
            limit: 10
          }
        },
        traffic: {
          type: 'input',
          label: '周边交通'
        }
      }
      // formData: {
      //   status: 1
      // },
      // formConfig: {
      //   formDesc: {

      //   },
      //   order: []
      // }
    }
  },
  methods: {
    handleRequest(data) {
      // data.bloc_id = data.blocs[0]
      // data.store_id = data.blocs[1]
      placeCreate(data).then((response) => {
        if (response.code === 200) {
          this.$message.success(response.message)
          this.closePage()
        } else {
          this.$message.error(response.message)
        }
      })
      return Promise.resolve()
    },
    handleRequestSuccess() {},
    closePage() {
      this.$store.dispatch('app/closePage', {
        vm: this,
        fromName: this.$route.name,
        toName: 'diandi-place-place-list-index',
        params: {}
      })
    }
  }
}
</script>
